#!/usr/bin/perl
#
# Remove empty user records from the DB.
# Empty is defined as:
# - State frozen
# - email empty
# - hasfrozen() returns 0
#
use Counter;
use Fcntl;
use NoteHandler;
use Getopt::Long;

$count = 10;

GetOptions("test" => \$test,
	   "count=i" => \$count);


$users = Counter::open(O_RDWR);
@maybeempty = $users->select("state = 'frozen' and email is null limit $count");
warn "Got ", @maybeempty+0, " entries\n";
$n = new NoteHandler;
for $rec (@maybeempty) {
    $n->start($rec->key());
    if ($rec->hasfrozen()) {
	$n->done("Not empty");
    } else {
	$rec->delete if !$test;
	$n->done("empty - delete");
    }
}
$n->report();
